/**
 * 
 */
package com.suyx.job.service.area.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.springframework.stereotype.Service;

import com.suyx.job.entity.RoleInfo;
import com.suyx.job.entity.TuInfo;
import com.suyx.job.enums.SectEnums;
import com.suyx.job.utils.ImagePHash;
import com.suyx.job.utils.ImageUtils;
import com.suyx.job.utils.ScreenCapture;
import com.suyx.job.utils.SysStaticData;

/**
 * @author syx
 *
 */
@Service
public class GoToDymgAreaServiceImpl extends AbstractAreaService{

	@Override
	public boolean execute(String device, String path, String area) {
		try {
			String[] infos = SysStaticData.CA1.get("地狱迷宫").split("&");
			userCA1(device,infos);
			// 到达国境
			ImagePHash p = new ImagePHash();
			ScreenCapture.snapshot(device,path, "screen.png");
	        ImageUtils.cutPNG(new FileInputStream(path +"screen.png"),
	                new FileOutputStream(path + device +".png"), 15,409,49,37);
	        String image1 = p.getHash(new FileInputStream(new File(path + device + ".png")));
	        String image2 = p.getHash(new FileInputStream(new File(SysStaticData.SC_PIC_PATH +"chuangkou.png")));
	        int score9 =  p.distance(image1, image2);
	        if(score9 == 0){
	        	ScreenCapture.mouseClick(device, "392 492");
	        }
	        
			ScreenCapture.mouseClick(device, "70 667");
			Thread.sleep(2 * 1000L);
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "564 113");
			//关闭地图
			ScreenCapture.mouseClick(device, "1110 25");
			Thread.sleep(62 * 1000L);
			//到达地府
			ScreenCapture.mouseClick(device, "684 47");
			Thread.sleep(2 * 1000L);
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "616 179");
			//关闭地图
			ScreenCapture.mouseClick(device, "1133 75");
			Thread.sleep(30 * 1000L);
			//到达地狱迷宫1
			ScreenCapture.mouseClick(device, "786 142");
			Thread.sleep(2 * 1000L);
			
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "551 587");
			//关闭地图
			ScreenCapture.mouseClick(device, "1133 79");
			Thread.sleep(28 * 1000L);
			//到达地狱迷宫2
			ScreenCapture.mouseClick(device, "128 555");
			Thread.sleep(2 * 1000L);
			
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "1103 428");
			//关闭地图
			ScreenCapture.mouseClick(device, "1133 79");
			Thread.sleep(31 * 1000L);
			//到达地狱迷宫3
			ScreenCapture.mouseClick(device, "1403 455");
			Thread.sleep(2 * 1000L);
			
			//点击地图
			ScreenCapture.mouseClick(device, "148 38");
			ScreenCapture.mouseClick(device, "1068 598");
			//关闭地图
			ScreenCapture.mouseClick(device, "1133 79");
			Thread.sleep(24 * 1000L);
			//到达地狱迷宫4
			ScreenCapture.mouseClick(device, "1362 502");
			Thread.sleep(2 * 1000L);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean support(String area) {
		return SectEnums.DYMG.getCode().equals(area);
	}

	@Override
	public boolean goToPoint(RoleInfo roleInfo, String path, TuInfo tuInfo) {
		String device = roleInfo.getDevice();
		String area = tuInfo.getZuobiaoX()+" "+tuInfo.getZuobiaoY();
		// TODO Auto-generated method stub
		return false;
	}

}
